package com.firebird.app.kotlin.stock.ui.success

import android.R
import android.view.KeyEvent
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import butterknife.BindView
import butterknife.OnClick
import com.firebird.app.kotlin.stock.MainActivity
import com.firebird.app.kotlin.stock.base.BaseActivity
import com.firebird.app.kotlin.stock.R
import com.firebird.app.kotlin.stock.data.EventMessage
import com.firebird.app.kotlin.stock.ui.godeal.GoDealActivity
import com.firebird.app.kotlin.stock.ui.personal_center.PersonalActivity
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode


class VerifyPersonSuccessActivity : BaseActivity() {
    @BindView(R.id.back)
    var back: LinearLayout? = null
    @BindView(R.id.tv_title)
    var tvTitle: TextView? = null
    @BindView(R.id.tv_complete)
    var tvComplete: TextView? = null
    private var strMessage: String? = null
    override val layoutId: Int
        get() = R.layout.activity_verify_person_success

    override fun onStart() {
        super.onStart()
        EventBus.getDefault().register(this)
    }

    override fun initView() {
        tvTitle!!.text = "操作提示"
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    fun onReceiveMsg(message: EventMessage) {
        strMessage = message.getMessage()
    }

    @OnClick(R.id.back, R.id.tv_complete)
    fun onViewClicked(view: View) {
        when (view.id) {
            R.id.back -> {
                if (strMessage == "Person") {
                    toClass_EmptyTop(this, PersonalActivity::class.java)
                }
                if (strMessage == "Main") {
                    toClass_EmptyTop(this, MainActivity::class.java)
                }
                if (strMessage == "Deal") {
                    toClass_EmptyTop(this, GoDealActivity::class.java)
                }
            }
            R.id.tv_complete -> {
                if (strMessage == "Person") {
                    toClass_EmptyTop(this, PersonalActivity::class.java)
                }
                if (strMessage == "Main") {
                    toClass_EmptyTop(this, MainActivity::class.java)
                }
                if (strMessage == "Deal") {
                    toClass_EmptyTop(this, GoDealActivity::class.java)
                }
            }
        }
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (strMessage == "Person") {
                toClass_EmptyTop(this, PersonalActivity::class.java)
            }
            if (strMessage == "Main") {
                toClass_EmptyTop(this, MainActivity::class.java)
            }
            if (strMessage == "Deal") {
                toClass_EmptyTop(this, GoDealActivity::class.java)
            }
        }
        return true
    }

    override fun onDestroy() {
        super.onDestroy()
        EventBus.getDefault().unregister(this)
    }
}